package com.example.questions.service.impl;

import com.example.questions.dao.CommonDirectoryDao;
import com.example.questions.dao.InterviewQuestionsDao;
import com.example.questions.entity.CommonDirectory;
import com.example.questions.entity.InterviewQuestions;
import com.example.questions.service.CommonDirectoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (CommonDircetory)表服务实现类
 *
 * @author makejava
 * @since 2023-07-02 22:33:04
 */
@Service("commonDirectoryService")
public class CommonDirectoryServiceImpl implements CommonDirectoryService {
    @Resource
    private CommonDirectoryDao commonDirectoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param  id
     * @return 实例对象
     */
    @Override
    public CommonDirectory queryById(Integer id) {
        return this.commonDirectoryDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param commonDirectory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CommonDirectory> queryByPage(CommonDirectory commonDirectory, PageRequest pageRequest) {
        long total = this.commonDirectoryDao.count(commonDirectory);
        return new PageImpl<>(this.commonDirectoryDao.queryAllByLimit(commonDirectory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param commonDirectory 实例对象
     * @return 实例对象
     */
    @Override
    public CommonDirectory insert(CommonDirectory commonDirectory) {
        this.commonDirectoryDao.insert(commonDirectory);
        return commonDirectory;
    }

    /**
     * 修改数据
     *
     * @param commonDirectory 实例对象
     * @return 实例对象
     */
    @Override
    public CommonDirectory update(CommonDirectory commonDirectory) {
        this.commonDirectoryDao.update(commonDirectory);
        return this.queryById(commonDirectory.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param  主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.commonDirectoryDao.deleteById(id) > 0;
    }

    @Override
    public List<CommonDirectory> queryAllClassification() {
        return commonDirectoryDao.queryAllClassification();
    }
}
